package chunk.model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import chunk.control.GameManager;
import wucoke.tools.HeroDirection;

public class Hero extends Shape {

	private HeroDirection dir = HeroDirection.STOP;

	private boolean isDown = false;
	private boolean isLeft = false;

	private boolean isRight = false;

	private boolean isStop = true;

	private boolean isUP = false;

	public Hero(int x, int y, int width, int heigth, int speed, Color color,
			GameManager gameManager) {

		super(x, y, width, heigth, speed, color, gameManager);

	}

	@Override
	public void drawSelf(Graphics g) {
		
		Color c = g.getColor();
		g.setColor(this.getColor());
		g.fillRect(getX(), getY(), getWidth(), getHeight());
		g.setColor(c);

	}
	
	

	@Override
	public void move() {
		if (dir == HeroDirection.D) {
			int y = getY();
			y += getSpeed();
			setY(y);
		} else if (dir == HeroDirection.UP) {
			int y = getY();
			y -= getSpeed();
			setY(y);
		} else if (dir == HeroDirection.L) {
			int x = getX();
			x -= getSpeed();
			setX(x);
		} else if (dir == HeroDirection.R) {
			int x = getX();
			x += getSpeed();
			setX(x);
			
		} else if (dir == HeroDirection.LU) {
			int x = getX();
			x -= getSpeed();
			setX(x);
			
			int y = getY();
			y -= getSpeed();
			setY(y);
		}else if (dir == HeroDirection.LD) {
			int x = getX();
			x -= getSpeed();
			setX(x);
			
			int y = getY();
			y += getSpeed();
			setY(y);
		}else if (dir == HeroDirection.RU) {
			int x = getX();
			x += getSpeed();
			setX(x);
			
			int y = getY();
			y -= getSpeed();
			setY(y);
		}else if (dir == HeroDirection.RD) {
			int x = getX();
			x += getSpeed();
			setX(x);
			
			int y = getY();
			y += getSpeed();
			setY(y);
		}

	}
	
	public void changDir() {

		if (isLeft && !isDown && !isRight && !isUP) {
			dir = HeroDirection.L;
		} else if (!isLeft && isDown && !isRight && !isUP) {
			dir = HeroDirection.D;
		} else if (!isLeft && !isDown && isRight && !isUP) {
			dir = HeroDirection.R;
		} else if (!isLeft && !isDown && !isRight && isUP) {
			dir = HeroDirection.UP;
		}

		else if (isLeft && !isDown && !isRight && isUP) {
			dir = HeroDirection.LU;
		} else if (isLeft && isDown && !isRight && !isUP) {
			dir = HeroDirection.LD;
		} else if (!isLeft && !isDown && isRight && isUP) {
			dir = HeroDirection.RU;
		} else if (!isLeft && isDown && isRight && !isUP) {
			dir = HeroDirection.RD;
		}
		
	

	}

	public HeroDirection getDir() {
		return dir;
	}

	public boolean isDown() {
		return isDown;
	}

	public boolean isLeft() {
		return isLeft;
	}

	public boolean isRight() {
		return isRight;
	}

	public boolean isStop() {
		return isStop;
	}

	public boolean isUP() {
		return isUP;
	}

	public void setDir(HeroDirection dir) {
		this.dir = dir;
	}

	public void setDown(boolean isDown) {
		this.isDown = isDown;
	}

	public void setLeft(boolean isLeft) {
		this.isLeft = isLeft;
	}

	public void setRight(boolean isRight) {
		this.isRight = isRight;
	}

	public void setStop(boolean isStop) {
		this.isStop = isStop;
	}

	public void setUP(boolean isUP) {
		this.isUP = isUP;
	}



}
